import '../model/result_model.dart';
import '../model/school_class_model.dart';
import '../utils/request.dart';

///学校班级接口
class SchoolClassApi {
  SchoolClassApi._();

  static final _singleton = SchoolClassApi._();

  factory SchoolClassApi() => _singleton;

  ///查询
  Future<SchoolClassQueryRes> query(final SchoolClassQueryReq req) => request
      .getHandler(path: '/school/${req.schoolId}/class', params: req.toMap())
      .then((res) => SchoolClassQueryRes.fromModel(res));

  ///加载
  Future<SchoolClassInfoRes> info(final String id) => request
      .getHandler(path: '/school/class/$id')
      .then((res) => SchoolClassInfoRes.fromModel(res));

  ///新增
  Future<BaseModelRes> add(final SchoolClassAddReq req) => request.postHandler(
      path: '/school/${req.schoolId}/class', data: req.toMap());

  ///修改
  Future<BaseModelRes> modify(final SchoolClassModifyReq req) =>
      request.putHandler(path: '/school/class/${req.id}', data: req.toMap());

  ///删除
  Future<BaseModelRes> delete(final String id) =>
      request.deleteHandler(path: '/school/class/$id');
}

//学校班级接口单例
final schoolClassApi = SchoolClassApi();
